package com.lbh.platforms.windows;

import com.lbh.platforms.windows.events.KeyDownEvent;
import com.lbh.platforms.windows.events.KeyUpEvent;
import com.lbh.platforms.windows.structures.user.WNDPROC;

import java.util.ArrayList;
import java.util.List;

import static com.lbh.platforms.windows.WinUser32.*;
import static com.lbh.platforms.windows.WinUser32.ins;

/***
 * project:JRuntime
 * package:com.lbh
 *
 * @author user:lenovo QQ:1601078366
 * @date 2021/10/20 1:22
 * @version V1.0
 */
public class WinEvent {

    public static final List<KeyDownEvent> keyDownEvents = new ArrayList<>();
    public static final List<KeyUpEvent> keyUpEvents = new ArrayList<>();

    public static final WNDPROC wndProc = (hwnd, uMsg, wParam, lParam) -> {
        switch (uMsg){
            case WM_CREATE:
                break;
            case WM_CLOSE:
                ins.PostQuitMessage(0);
                break;
            case WM_QUIT:
                break;
            case WM_DESTROY:
                break;
            case WM_KEYDOWN:
                for (KeyDownEvent event : keyDownEvents) {
                    event.onKeyDown(wParam);
                }
                break;
            case WM_KEYUP:
                for (KeyUpEvent event : keyUpEvents) {
                    event.onKeyUp(wParam);
                }
                break;
            default:
                break;
        }
        return ins.DefWindowProcA(hwnd, uMsg, wParam, lParam);
    };
}
